//
//  ParentViewController.m
//  traveling
//
//  Created by xiaoR on 16/3/26.
//  Copyright © 2016年 family. All rights reserved.
//

#import "ParentViewController.h"

#define searchWidth ScreenWidth * .63

@implementation ParentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}

- (void)createNavigationBar:(NSInteger)setting{
    //    自定义的状态栏背景
    self.navigationBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    self.navigationBarView.backgroundColor = ColorNavigation;
    
    if (setting%2 == 1) {//1 = 1 右边的按钮
        self.buttonA = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 36, 30, 24, 24)];
        [self.buttonA addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationBarView addSubview:self.buttonA];
    }
    
    if ((setting>>1) %2 == 1){//10 = 2 中间的搜索页面
        //    搜索框使用UITextField
        self.textField = [[DiyUITextField alloc] initWithFrame:CGRectMake(ScreenWidth - 50 - searchWidth, 26, searchWidth, 30)];
        self.textField.textColor = RGBA(255, 255, 255, .8);
        self.textField.layer.cornerRadius = 15.f;
        self.textField.placeholder = @"输入作物/产品";
        [self.textField setValue:RGBA(255, 255, 255, .8) forKeyPath:@"_placeholderLabel.textColor"];
        self.textField.font = [UIFont systemFontOfSize:12.f];
        self.textField.backgroundColor = RGBA(0, 0, 0, .3);
        
        self.textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SearchIcon"]];
        self.textField.leftViewMode = UITextFieldViewModeAlways;
        
        self.textField.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"QRCodeIcon"]];
        self.textField.rightViewMode = UITextFieldViewModeAlways;
        
        [self.textField layoutIfNeeded];
        [self.navigationBarView addSubview:self.textField];
    }
    if((setting>>2) %2 == 1){//100 = 4 定位专用
        
        _location = [[UILabel alloc] init];
        _location.text = @"上海";
        _location.textColor = [UIColor whiteColor];
        _location.frame = CGRectMake((ScreenWidth - searchWidth - 50 - 18 * _location.text.length - 15) / 2, 34, 18 * _location.text.length, 16);
        [_navigationBarView addSubview:_location];
        
        _image = [[UIImageView alloc] initWithFrame:CGRectMake(_location.width + _location.left, 32, 12, 24)];
        _image.image = [UIImage imageNamed:@"DownArrowIcon"];
        [_navigationBarView addSubview:_image];
        
        _buttonTitle = [[UIButton alloc] initWithFrame:CGRectMake(0, 24, ScreenWidth - searchWidth - 50 ,32)];
        [_buttonTitle addTarget:self action:@selector(leftTitleAction) forControlEvents:UIControlEventTouchUpInside];
        [_navigationBarView addSubview:_buttonTitle];
    }
    
    if((setting>>3) %2 == 1){
        
        UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 27, 12, 30)];
        image.image = [UIImage imageNamed:@"LeftArrowWhiteIcon"];
        [self.navigationBarView addSubview:image];
        
        UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 63, ScreenWidth, 1)];
        line.backgroundColor = RGB(216, 216, 216);
        [self.navigationBarView addSubview:line];
        
        
        _back = [[UILabel alloc] init];
        _back.text = @"返回";
        _back.frame = CGRectMake(ScreenWidth / 2 - 80, 34, 160, 16);
        _back.textAlignment = NSTextAlignmentCenter;
        _back.textColor = [UIColor whiteColor];
        [_navigationBarView addSubview:_back];
        _backTitle2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, ScreenWidth - searchWidth - 50 ,32)];
        [_backTitle2 addTarget:self action:@selector(backTitleAction) forControlEvents:UIControlEventTouchUpInside];
        [_navigationBarView addSubview:_backTitle2];
//        [_navigationBarView addSubview:[Factory createViewWithBackgroundColor:ColorNavigation frame:CGRectMake(0, 63.5, ScreenWidth, 1)]];
    }
    
    
    [self.view addSubview:_navigationBarView];
}

- (void)rightButtonAction {
//    [self presentViewController:[NLianSearchViewController new] animated:YES completion:nil];
}

- (void)leftTitleAction {
    NSLog(@"button1");
}

- (void)backTitleAction {
//    self.tabBarController.selectedIndex = 0;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
